Skip to content

Conversation

@NoelStephensUnity
Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity commented Sep 9, 2025

Purpose of this PR

This PR resolves the issue where setting SwitchTransformSpaceWhenParented to true and then setting InLocalSpace to true will force the motion authority to continually send updates each tick (whether there is a delta or not).

Jira ticket

MTTB-1584

fix: #3653
fix: #3646
fix: #3645

Changelog

  • Added: NetworkRigidbody documentation section.
  • Fixed: NetworkTransform state synchronization issue when NetworkTransform.SwitchTransformSpaceWhenParented is enabled and the associated NetworkObject is parented multiple times in a single frame or within a couple of frames.
  • Fixed: Issue when spawning, parenting, and immediately re-parenting.
  • Changed: NetworkShow sends a message and forces a NetworkVariable synchronization at the end of the frame prior to generating the CreateObjectMessage as opposed to waiting until the next network tick to synchronize the show with the update to NetworkVariables.
  • Changed: NetworkTransform now synchronizes NetworkTransform.SwitchTransformSpaceWhenParented when it is updated by the motion model authority.
  • Changed: NetworkObjects pending to be shown to clients can now occur on partial network ticks. If any pending NetworkObjects pending to be shown to clients happens to be ready on a new network tick they still are shown after network variable deltas have been processed.
  • Changed: The default NetworkDelivery used by all messages is now reliable fragmented sequenced with the exception of named, unnamed, and any messages sent with a user specified network delivery type. This assures certain order of operations to be preserved when same call-stack changes are applied to a newly spawned, authority side, NetworkObject.
  • Changed: NetworkTransform documentation to better reflect the Teleport methods intended usage along with updates to NetworkObject and physics areas of the documentation.

Documentation Included

  • Includes documentation for existing public API entry points:
    • Updates to the SwitchTransformSpaceWhenParented XML API that provides additional information about usage.
    • Updates to the SetState and Teleport for more clarity on intended usage for both network topologies.
    • Updates to NetworkObject.SpawnWithOwnership to call out how spawning with ownership can impact things like NetworkTransform during the spawning sequence when using a client-server topology.
  • Includes updates to existing documentation:
    • Updates to NetworkTransform regarding the use of SwitchTransformSpaceWhenParented.
      • Add section covering spawning, order of operations, and how timing and network topology can impact the end result.
        • Include SetState/Teleport, spawning (with or without) ownership, and the authority motion model.
    • Updates to the NetworkObject spawning section
      • Expand the coverage to include:
        • Spawning then changing ownership vs SpawnWithOwnership
        • Spawning, NetworkTransform, and parenting.
    • Updated physics
      • Includes parenting physics objects using attachables.
    • Added a first pass (still could use some additions in the future) NetworkRigidbody section (pulled this part out of physics).

Testing & QA (How your changes can be verified during release Playtest)

  • Includes an integration test to validate the fix (NetworkTransformAutoParenting)
  • Includes several additional integration tests via NetworkTransformOrderOfOperations to validate other edge case scenarios:
    • Test-1:
      • Server-> Spawn, change ownership, (wait), parent
    • Test-2:
      • Server-> Spawn, change parent, change ownership
    • Test-3:
      • Server-> Spawn, change parent (1), change ownership
      • Client-> PostSpawn re-parent (2)
    • Test-4:
      • Server-> Spawn no observers, change parents (multiple), NetworkShow, change ownership, Teleport RPC
      • Client-> Teleport RPC
    • Test-5:
      • Server-> Spawn, change parent (1), change ownership, Teleport RPC with NetworkBehaviourReference
      • Client-> Teleport RPC using NetworkBehaviourReference
    • Test-6:
      • Server-> Spawn, change ownership, change parent (1), Teleport RPC with NetworkBehaviourReference
      • Client-> Teleport RPC using NetworkBehaviourReference
    • Test-7:
      • Server-> Spawn with ownership, change parent (1), Teleport RPC with NetworkBehaviourReference
      • Client-> Teleport RPC using NetworkBehaviourReference
    • Test 8:
      • Server-> Start coroutine:
        • Coroutine: Spawn with no observers, change parent (1), NetworkShow, change ownership, Teleport RPC with NetworkBehaviourReference
      • Client-> Teleport RPC using NetworkBehaviourReference.
    • Test 9:
      • Server-> Start coroutine:
        • Coroutine: Spawn with no observers, NetworkShow, change parent (1)
    • Test 10:
      • Server-> Spawn with ownership, change parent (1), Wait (1), Parent RPC with NetworkObjectReference
      • Client-> Re-parent (2) RPC using NetworkObjectReference
    • Test 11:
      • Server-> Spawn with ownership, Parent RPC with NetworkObjectReference,
      • Client-> Parent (1) RPC using NetworkObjectReference
      • Server-> Parent changed --> parent under 2nd object (was a delay, but the recommended way will be to wait if you know the client is going to parent.
  • Includes a manual test (need to import this small test into our manual tests)

Functional Testing

Manual testing :

  • [ X ] Manual testing done
    • The original CharacterControllerMovingBodies project.
      • This verifies the existing functionality was not broken.
    • The manual test mentioned above that was used to replicate the user's issues and fix them.
      • This verifies (n) parenting events can occur on a single frame and it will be synchronized.

Automated tests:

  • Covered by existing automated tests
  • [ X ] Covered by new automated tests
    • (wip)

Does the change require QA team to:

  • Review automated tests?
  • Execute manual tests?
  • Provide feedback about the PR?

If any boxes above are checked the QA team will be automatically added as a PR reviewer.

Backports

This is an NGO v2.x.x specific issue. No backport is required.

Assure that the local InLocalSpace field is updated to match the parented status.
Reset IsTeleporting and ExplicitSet after invoking OnAuthorityPushTransformState so these values are preserved for user script.

Automatically adjust InLocalSpace when spawning a NeworkObject based on the NetworkObject's current parented status when SwitchTransformSpaceWhenParented is enabled.
Invoking the OnAuthorityPushTransformState and OnNetworkTransformStateUpdated when synchronizing in order to provide users with the NetworkTransformState used to synchronize a NetworkTransform when first spawned.
Revert moving where IsTeleportingNextFrame and ExplicitSet are reset.
Add WasTeleported to NetworkTransformState in order to preserve whether the pushed state was teleported or not.
Adding documentation updates.
XML API update
Copy link
Contributor

@jabbacakes jabbacakes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left suggestions on the smaller changes - have pushed a commit with changes to the larger new additions to the NetworkTransform page, mostly just trying to improve clarity and reduce verbiage.

This page is getting very long, might break it up at some point, but will do that in a separate PR.

NoelStephensUnity and others added 8 commits September 12, 2025 13:55
NetworkSpawnManager:
Relative to spawning only, process deferred messages after post spawn.

NetworkTransform:
Synchronize the SwitchTransformSpaceWhenParented flag when it changes on the authority side.
Perform an early check in CheckForStateChange for changes to SwitchTransformSpaceWhenParented.
Apply changes to SwitchTransformSpaceWhenParented when processing a state update on non-authority instance.
A complete refactoring of how parenting is handled when NetworkTransform.SwitchTransformSpaceWhenParented is enabled to provide a complete 1:1 match of (n) back-to-back parenting actions and/or many parenting actions that occur over several frames. This preserves the order of operations, sends 1 full state update plus an added parenting directive per action immediately, and then upon receiving the non-authority instances will apply the parenting, transform the local values and interpolators' queued entries  between transform spaces (world to local, local to world, or local to local).
@NoelStephensUnity
Copy link
Collaborator Author

/ci ngo

Standards/style fix.
@NoelStephensUnity
Copy link
Collaborator Author

/ci ngo

More hidden white spaces...
@NoelStephensUnity
Copy link
Collaborator Author

/ci ngo

Removing one line space
@NoelStephensUnity
Copy link
Collaborator Author

/ci ngo

@NoelStephensUnity NoelStephensUnity marked this pull request as ready for review September 15, 2025 13:31
@NoelStephensUnity NoelStephensUnity requested a review from a team as a code owner September 15, 2025 13:31
@NoelStephensUnity NoelStephensUnity enabled auto-merge (squash) October 15, 2025 16:45
Copy link
Collaborator

@EmandM EmandM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR was genuinely a joy to review :godmode:

So many nice things in here I couldn't begin to list them all. Most of my comments are small nit picks. Overall this looks so clean and nice and wonderful I don't even have enough words to say how much I like it.

NoelStephensUnity and others added 19 commits October 16, 2025 15:01
Minor merge fixes to table of contents.
Helper URLs now point to the rigidbody documentation.
Adding to be used best practices marker.
Fixing some [!NOTE] sections where text was on the same line (which breaks the notation check when converting the documentation).
Removing trailing white space
replaced .md with .html
HelpURL tests now check to see if the document exists before failing if it can't be loaded from the latest documentation update.

Adjusted the HelpUrls base portions of the URL so they are internal.
Using System.IO.File.
Migrating into the testproject's runtime tests.
Encapsulating within UNITY_EDITOR define.
Removed the iPhone platform exclusion.
Fixing import issue.
Removing duplicate logic checks in despawn.
Adding comment.
Refactoring the NetworkObject check.
Adjusting test and version bump
@NoelStephensUnity NoelStephensUnity merged commit 47ae1ea into develop-2.0.0 Oct 18, 2025
24 checks passed
@NoelStephensUnity NoelStephensUnity deleted the fix/networktransform-autoswitchspace-forcing-updates-localspace branch October 18, 2025 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants